<template>
	<div style="height: 100%;">

		<el-dialog :visible.sync="visible1" top="2%" :title="(form.defenceName?form.defenceName:'')+'的防治设施信息'"
			width="90%" @close="closeDialog" append-to-body>
			<el-tabs :value="activeName" @tab-click="handleClick">
				<el-tab-pane label="防治设施基本信息" name="one">
					<el-form ref="form" :model="form" :rules="formRules" label-width="140px" label-position="right">
						<el-form-item label="图片">
							<div>
								<el-upload ref="upload" :limit="1" :multiple="false" action="#" :auto-upload="false"
									:on-change="changeFile" :on-remove="()=>{form.imgId = ''}" list-type="picture-card"
									:file-list="fileList">
									<i class="el-icon-plus"></i>
								</el-upload>
							</div>
						</el-form-item>
						<el-form-item label="防治设施设备名称" prop="defenceName">
							<el-input v-model="form.defenceName" style="width: 300px;"></el-input>
						</el-form-item>
						<el-form-item label="防治设施设备类型" prop="defenceType">
							<el-select v-model="form.defenceType" style="width: 300px;" filterable>
								<el-option :label="item1.label" :value="item1.value"
									v-for="(item1,index1) in defenceTypeList">
								</el-option>
							</el-select>
						</el-form-item>

						<el-form-item label="防治设施设备编号" prop="defenceNo">
							<el-input :value="form.defenceNo" style="width: 300px;"
								@input="(value)=>{form.defenceNo = value,$forceUpdate()}"></el-input>
						</el-form-item>
						<el-form-item label="防治设施设备型号" prop="defenceModel">
							<el-input v-model="form.defenceModel" style="width: 300px;"></el-input>
						</el-form-item>

						<el-form-item label="危废产生源" prop="hwSourceId">
							<el-select v-model="form.hwSourceId" style="width: 300px;" filterable clearable>
								<el-option :label="item1.sourceName" :value="item1.id"
									v-for="(item1,index1) in hwSourceList">
								</el-option>
							</el-select>
						</el-form-item>

						<el-form-item label="固废产生源" prop="swSourceId">
							<el-select v-model="form.swSourceId" style="width: 300px;" filterable clearable>
								<el-option :label="item1.sourceName" :value="item1.id"
									v-for="(item1,index1) in swSourceList">
								</el-option>
							</el-select>
						</el-form-item>

						<el-form-item label="启用时间" prop="useDate">
							<el-date-picker v-model="form.useDate" style="width: 300px;" type="date" placeholder="启用时间"
								value-format="yyyy-MM-dd">
							</el-date-picker>
						</el-form-item>
						
						<el-form-item label="视频监控" prop="videoIdList">
							<el-select v-model="form.videoIdList" style="width: 300px;" filterable clearable multiple>
								<el-option :label="item1.equipmentPosition" :value="item1.id"
									v-for="(item1,index1) in videoList">
								</el-option>
							</el-select>
						</el-form-item>

						<div style="text-align: center;">
							<el-button type="primary" @click="saveInfo(1)">保存</el-button>
						</div>
					</el-form>
				</el-tab-pane>

				<el-tab-pane label="主要规格参数" name="two">
					<el-form ref="form2" label-width="100px">
						<div class="displayFlex">
							<el-form-item label="设备DCS" prop="dcsMn" class="mr10">
								<el-input v-model="form.dcsMn" style="width: 278px;" @change="getDscRunList"
									@blur="getDscRunList"></el-input>
							</el-form-item>
							<el-form-item label="开关DCS" prop="dcsRun" class="mr10">
								<el-select v-model="form.dcsRun" style="width: 300px;" filterable>
									<el-option :label="item1.name" :value="item1.code"
										v-for="(item1,index1) in dcsRunList">
									</el-option>
								</el-select>
							</el-form-item>
							<el-form-item label="开关标准值" prop="dcsRunStd" class="mr10">
								<el-input v-model="form.dcsRunStd" type="number"></el-input>
							</el-form-item>
						</div>
						<div v-for="(item,index) in parameter.list" :key="index">
							<div class="displayFlex">
								<el-form-item :label="'规格参数'+(index+1)" prop="parameterName" style="flex: 1;">
									<el-input v-model="item.parameterName" placeholder="规格参数"></el-input>
								</el-form-item>
								<el-form-item label="类型" prop="parameterType" style="flex: 1;">
									<el-select v-model="item.parameterType" style="width: 100px;" filterable>
										<el-option label="普通" value="COMMON" />
										<el-option label="出口流量" value="WATER_VOLUME" />
									</el-select>
								</el-form-item>
								<el-form-item label="范围" prop="designValueStr" style="flex: 1.5;">
									<div class="displayFlex">
										<el-input v-model="item.minDesignValue" placeholder="最小值"
											type="number"></el-input>
										<span class="ml5 mr5">～</span>
										<el-input v-model="item.maxDesignValue" placeholder="最大值"
											type="number"></el-input>
									</div>
								</el-form-item>
								<el-form-item label="单位" prop="unitCode" style="flex: 1;">
									<el-input v-model="item.unitCode" placeholder="单位"></el-input>
								</el-form-item>
								<el-form-item label="DCS设备" prop="dcsMn" style="flex: 1;">
									<el-input v-model="item.dcsMn" placeholder="DCS设备"></el-input>
								</el-form-item>

								<el-form-item label="DCS参数" prop="dcsCode" style="flex: 1;">
									<el-select v-model="item.dcsCode" filterable
										@focus="getEachDscRunList($event,item,index)">
										<el-option :label="item1.name" :value="item1.code"
											v-for="(item1,index1) in dcsAllRunList[index]">
										</el-option>
									</el-select>
								</el-form-item>
								<div style="width: 80px;text-align: right;color: #F56C6C;margin-bottom: 20px;"
									@click="deleteParameter(index)">
									删除
								</div>
							</div>
						</div>
						<div @click="addParameter" style="color: #3a3ef4;" class="point">添加规格参数</div>

						<div style="text-align: center;">
							<el-button type="primary" @click="saveParameter(1)">保存</el-button>
							<!-- <el-button type="primary" @click="saveParameter(2)">保存并继续</el-button> -->
						</div>
					</el-form>
				</el-tab-pane>

				<el-tab-pane label="巡检项" name="four">
					<div v-if="parameterInspectStatusList.length > 0">
						<div class="font15 color333 u-font-bold"
							style="padding-bottom: 10px;border-bottom: 1px solid#f5f5f5;">
							巡检参数
						</div>
						<div class="mt10">
							<div v-for="(item,index) in parameterInspectStatusList" :key="index">
								<el-form-item :label="item.parameterName" prop="isInspect">
									<el-radio-group v-model="item.isInspect" class="displayFlex pt8 ml20"
										@input="updateParameterInspectStatus($event,item)">
										<el-radio :label="true">巡检</el-radio>
										<el-radio :label="false">不巡检</el-radio>
									</el-radio-group>
								</el-form-item>
							</div>
						</div>
					</div>

					<div>
						<div class="font15 color333 u-font-bold mb10 pb10" style="border-bottom: 1px solid#f5f5f5;">
							其它巡检项
						</div>

						<el-form ref="form2" label-width="100px">
							<div v-for="(item,index) in inspectItemList" :key="index">
								<div class="displayFlex">
									<el-form-item :label="'巡检项名称'+(index+1)" prop="inspectItemName">
										<el-input v-model="item.inspectItemName" placeholder="巡检项信息"></el-input>
									</el-form-item>

									<el-form-item label="记录值类型" prop="valueType">
										<el-select v-model="item.valueType" placeholder="记录值类型" style="width: 100%;">
											<el-option label="数值" value="NUMBER" />
											<el-option label="状态" value="STATE" />
										</el-select>
									</el-form-item>


									<template v-if="item.valueType == 'NUMBER'">
										<el-form-item label="最小值" prop="minLimit">
											<el-input v-model="item.minLimit" placeholder="最小值"
												type="number"></el-input>
										</el-form-item>

										<el-form-item label="最大值" prop="maxLimit">
											<el-input v-model="item.maxLimit" placeholder="最大值"
												type="number"></el-input>
										</el-form-item>

										<el-form-item label="单位" prop="unitCode">
											<el-input v-model="item.unitCode" placeholder="单位"></el-input>
										</el-form-item>
									</template>

									<div style="width: 80px;text-align: right;color: #F56C6C;margin-bottom: 20px;"
										@click="inspectItemList.splice(index,1)">
										删除
									</div>
								</div>
							</div>
							<div @click="inspectItemList.push({inspectItemName:'',valueType:'NUMBER'})"
								style="color: #3a3ef4;" class="point">
								添加巡检项
							</div>

							<div style="text-align: center;">
								<el-button type="primary" @click="saveInspectItem(1)">保存</el-button>
							</div>
						</el-form>
					</div>

					<!-- <el-button style="margin-left: 10px;height: 32px;line-height: 30px; padding-top: 0; padding-bottom: 0;"
						class="mt10" size="small"
						@click="xunjian.show=true,xunjian.params = $options.data().xunjian.params,$forceUpdate()">
						+ 添加巡检项
					</el-button> -->
				</el-tab-pane>

				<el-tab-pane label="原辅料" name="three">

					<div class="mb10 font14 point" style="color: #3a3ef4;" @click="gotoAdd"
						v-if="materialList.length > 0">原辅料中没有需要的材料，请去原辅材料库添加新材料。</div>
					<el-form ref="form3" label-width="100px">
						<div v-for="(item,index) in materialList" :key="index">
							<div class="displayFlex">
								<el-form-item :label="'原辅料'+(index+1)" prop="materialId">
									<el-select v-model="item.materialId" filterable placeholder="名称"
										style="width: 250px;">
										<el-option v-for="item in materialChooseList" :key="item.id"
											:label="item.materialName" :value="item.id">
										</el-option>
									</el-select>
								</el-form-item>

								<el-form-item label="更换周期" prop="frequency">
									<el-input v-model="item.frequency" style="width: 300px;"
										placeholder="更换周期"></el-input>
								</el-form-item>

								<div style="width: 80px;text-align: right;color: #F56C6C;margin-bottom: 20px;"
									@click="materialList.splice(index,1)" v-if="index > 0">
									删除
								</div>
							</div>
						</div>
						<div @click="materialList.push({materialId:'',frequency:''})" style="color: #3a3ef4;"
							class="point">
							添加原辅料
						</div>

						<div style="text-align: center;">
							<el-button type="primary" @click="saveMaterial(1)">保存</el-button>
						</div>
					</el-form>
				</el-tab-pane>

				<el-tab-pane label="污染物" name="seven">

					<div class="displayFlexBet mb10" style="flex-wrap:wrap">
						<div v-for="(item,index) in pollutionList" :key="index" style="width:50%" class="mb10">
							<div class="displayFlex">
								<el-checkbox v-model="item.isSelect" :label="item.pollutionName" style="width:100px">
									{{item.pollutionName}}
								</el-checkbox>

								<div class="displayFlex mr20">
									<el-input v-model="item.efficiency" style="width: 100px;" placeholder="处置效率"
										class="ml10" :disabled="!item.isSelect" :max="100" :min="0"
										type="number"></el-input>
									<span class="ml10">%</span>
								</div>


								<el-select v-model="item.source" placeholder="数据来源" style="width: 100px;">
									<el-option label="设备厂商" value="设备厂商" />
									<el-option label="环评" value="环评" />
								</el-select>
							</div>
						</div>
					</div>


					<div style="text-align: center;">
						<el-button type="primary" @click="savePollutionList(1)">保存</el-button>
					</div>
				</el-tab-pane>

				<el-tab-pane v-if="form.isEdit" label="二维码" name="six">
					<div style="margin-bottom: 10px;text-align: center;">
						<vue-qr :text="form.id" :size="250" />
						<div style="font-weight: bold">{{form.defenceName}}</div>
					</div>
				</el-tab-pane>

			</el-tabs>
		</el-dialog>

		<el-dialog v-if="visible3" :visible.sync="visible3" top="2%" title="原辅料信息" :modal="false" width="30%"
			append-to-body>
			<el-form ref="form3" :model="material" :rules="formRules3" label-width="140px">
				<el-form-item label="原辅料" prop="materialId">
					<el-select v-model="material.materialId" filterable placeholder="名称" style="width: 250px;">
						<el-option v-for="item in materialChooseList" :key="item.id" :label="item.materialName"
							:value="item.id">
						</el-option>
					</el-select>
				</el-form-item>

				<div style="text-align: center;margin-top: 50px;">
					<el-button type="primary" @click="saveMaterial(1)">保存</el-button>
				</div>
			</el-form>
		</el-dialog>

		<el-dialog :visible.sync="xunjian.show" top="2%" title="巡检项信息" :modal="false" width="30%" append-to-body>
			<el-form :model="xunjian.params" label-width="140px" :rules="rules2">
				<el-form-item label="巡检项名称" prop="inspectItemName" required>
					<el-input v-model="xunjian.params.inspectItemName" placeholder="巡检项信息"></el-input>
				</el-form-item>

				<el-form-item label="记录值类型" prop="valueType">
					<el-select v-model="xunjian.params.valueType" placeholder="记录值类型" style="width: 100%;">
						<el-option label="数值" value="NUMBER" />
						<el-option label="状态" value="STATE" />
					</el-select>
				</el-form-item>

				<div style="text-align: center;margin-top: 50px;">
					<el-button type="primary" @click="saveXunJian(1)">保存</el-button>
				</div>
			</el-form>
		</el-dialog>
	</div>
</template>

<script>
	let APPKEY = '5da5441f62e48aedc7a3853ffc75c2db';
	let PRODID = 'gf';
	let UPLOAD_ACTION = '/upload';
	let VIEW_ACTION = '/view';
	let REMOVE_ACTION = '/remove';
	let IMGURL = 'https://www.weifeibangbang.com/wfbb-webupload/service/sys/file/upload';
	let fileViewUrl =
		'https://www.weifeibangbang.com/wfbb-webupload/service/sys/file/upload/view?appKey=5da5441f62e48aedc7a3853ffc75c2db&prodID=gf&fileID='
	let that
	import VueQr from 'vue-qr'
	import $ from 'jquery'
	export default {
		props: ['outletId'],
		components: {
			VueQr
		},
		data() {
			return {
				dataList: [],
				params: {
					ticketId: '',
				},
				visible1: false,
				visible2: false,
				visible3: false,
				activeName: 'one',
				form: {
					defenceNo: '',
					useDate: '',
					dcsMn: '',
					dcsRun: '',
					dcsRunStd: '',
					imgId: '',
					videoIdList: []
				},
				parameter: {
					list: []
				},
				production: {
					relationList: []
				},
				material: {
					materialType: '',
					ingredientList: []
				},
				xunjian: {
					show: false,
					params: {
						defenceId: '', // 防治设施id
						inspectItemName: '', // 巡检项名称
						valueType: 'NUMBER', // 记录值类型
					}
				},
				rules2: {
					inspectItemName: [{
						required: true,
						message: '巡检项信息',
						trigger: 'blur'
					}]
				},
				formRules: {
					defenceName: [{
						required: true,
						message: '防治设施设备名称',
						trigger: 'blur'
					}],
					defenceType: [{
						required: true,
						message: '防治设施类型',
						trigger: 'blur'
					}],
					// technologyId: [{
					// 	required: true,
					// 	message: '生产项目',
					// 	trigger: 'blur'
					// }]
				},

				formRules2: {
					productType: [{
						required: true,
						message: '产品类型',
						trigger: 'blur'
					}],
					productName: [{
						required: true,
						message: '产品名称',
						trigger: 'blur'
					}],
					unitCode: [{
						required: true,
						message: '防治设施型号',
						trigger: 'blur'
					}],
					maxProductionQty: [{
						required: true,
						message: '防治设施生产能力',
						trigger: 'blur'
					}]
				},

				formRules3: {
					materialName: [{
						required: true,
						message: '名称',
						trigger: 'blur'
					}]
				},
				unitList: [],
				productList: [], //已添加的产品列表
				materialList: [], //原辅料列表
				materialChooseList: [],
				waterTechnologyList: [],
				inspectItemList: [], //巡检项
				parameterInspectStatusList: [],
				pageIndex: 0,
				totalPage: 0,
				parameterTypelist: [{
					label: "普通",
					value: "COMMON"
				}, {
					label: "高度",
					value: "HEIGHT"
				}, {
					label: "烟气",
					value: "SMOKE"
				}, {
					label: "温度",
					value: "TEMPERATURE"
				}, {
					label: "压力",
					value: "PRESSURE"
				}, {
					label: "耗电量",
					value: "ELECTRICITY"
				}, {
					label: "排放时间",
					value: "OUTLETTIME"
				}],
				defenceTypeList: [{
					label: "排口",
					value: "OUTLET"
				}, {
					label: "格栅",
					value: "GRILLE"
				}, {
					label: "沉淀池",
					value: "SETTLING_TANK"
				}, {
					label: "气浮设备",
					value: "AIR_FLOTATION"
				}, {
					label: "过滤设备",
					value: "FILTER"
				}, {
					label: "曝气设备",
					value: "AERATION"
				}, {
					label: "生物反应器",
					value: "BIOLOGICAL_REACTION"
				}, {
					label: "加药装置",
					value: "DOSING"
				}, {
					label: "膜组件",
					value: "MEMBRANE"
				}, {
					label: "污泥脱水设备",
					value: "DE_WATERING"
				}, {
					label: "消毒设备",
					value: "DISINFECTION"
				}, {
					label: "其他",
					value: "OTHER"
				}],
				hwSourceList: [],
				swSourceList: [],
				pollutionList: [],
				dcsRunList: [],
				dcsAllRunList: [],
				videoList: [],
			}
		},

		mounted: function() {
			that = this
			that.params.ticketId = that.$store.state.token

			that.ajax({
				url: '/codeType/listCodeValue',
				data: {
					typeCode: 'UNIT_TYPE'
				},
				success: function(data) {
					if (data.status == 1) that.unitList = data.data;
				}
			});

			that.ajax({
				url: '/hw/wasteSource/getSourceList',
				data: {},
				success: function(data) {
					if (data.status == 1) that.hwSourceList = data.data;
				}
			});

			that.ajax({
				url: '/sw/wasteSource/getSourceList',
				data: {},
				success: function(data) {
					if (data.status == 1) that.swSourceList = data.data;
				}
			});

			that.ajax({
				url: '/entAuxiliaryMaterial/getEntAuxiliaryMaterialList',
				data: JSON.stringify({}),
				contentType: 'application/json',
				success: function(result) {
					that.materialChooseList = result.data
				},
			})
			
			that.ajax({
				url: '/video/monitor/equipment/getListByEntId',
				data: {},
				success: function(data) {
					if (data.status == 1) that.videoList = data.data;
				}
			});
		},

		watch: {
			form(newValue, oldValue) {
				if (!newValue.isEdit) {
					if (newValue.defenceType && newValue.technologyId) {
						that.ajax({
							url: '/waterOutletDefence/getDefenceCode',
							data: {
								technologyId: newValue.technologyId, // 生产项目id
								defenceType: newValue.defenceType // 防治设施类型
							},
							success: function(data) {
								if (!that.form.defenceNo) that.form.defenceNo = data.data
								that.$forceUpdate()
							}
						});
					}
				}
			}
		},

		methods: {
			changeFile: function(file, fileList) {
				var _this = this;
				file.url = URL.createObjectURL(file.raw);

				var formdata = new FormData()
				formdata.append("file", file.raw);
				formdata.append("appKey", APPKEY);
				formdata.append("businessCode", that.randomChar(19));
				formdata.append("prodID", PRODID);
				$.ajax({
					url: IMGURL + '/upload',
					data: formdata,
					type: 'POST',
					dataType: 'json',
					contentType: false,
					processData: false,
					success: function(result) {
						var fileId = result.message.fileID;
						that.form.imgId = fileId
					},
					error: function() {}
				})
			},

			randomChar: function(l) {
				var x = "0123456789qwertyuioplkjhgfdsazxcvbnm";
				var tmp = "";
				var timestamp = new Date().getTime();
				for (var i = 0; i < l; i++) {
					tmp += x.charAt(Math.ceil(Math.random() * 100000000) % x.length);
				}
				return timestamp + tmp;
			},

			getEachDscRunList(e, item, index) {
				that.ajax({
					url: '/dcs/parameter/list',
					data: {
						mn: item.dcsMn,
					},
					contentType: 'application/x-www-form-urlencoded',
					success: function(result) {
						that.dcsAllRunList[index] = result.data
						that.$forceUpdate()
					},
				})
			},

			getDscRunList() {
				// if (!that.form.dcsMn) return that.$message.error("请输入设备dcs")
				that.ajax({
					url: '/dcs/parameter/list',
					data: {
						mn: that.form.dcsMn,
					},
					contentType: 'application/x-www-form-urlencoded',
					success: function(result) {
						that.dcsRunList = result.data
					},
				})
			},

			savePollutionList() {
				let dataList = []
				for (let item of that.pollutionList) {
					if (item.isSelect) dataList.push(item)
				}
				//if (dataList.length == 0) return that.$message.error("请选择污染物")
				that.ajax({
					url: '/waterOutletDefence/pollution/batchSave',
					data: JSON.stringify({
						defenceId: that.form.id,
						pollutionList: dataList,
					}),
					contentType: 'application/json',
					success: function(result) {
						if (result.data) {
							that.$message.success("保存成功！")
						}
					},
				})
			},

			gotoAdd() {
				that.$router.push("/wasteWater/materialManage")
			},

			updateParameterInspectStatus(e, item) {
				that.ajax({
					url: '/waterOutlet/updateParameterInspectStatus',
					data: JSON.stringify({
						parameterId: item.parameterId,
						isInspect: e
					}),
					contentType: 'application/json',
					success: function(result) {
						if (result.data) {}
					},
				})
			},

			closeDialog() {
				that.visible2 = false
				that.$emit("close", true)
			},

			//保存巡检项
			saveInspectItem() {
				// if (that.inspectItemList.length == 0) {
				// 	return that.$message({
				// 		message: '请填写巡检信息',
				// 		type: 'warning'
				// 	});
				// }
				that.xunjian.params.defenceId = that.form.id
				that.xunjian.params.list = that.inspectItemList
				that.ajax({
					url: '/waterOutletDefence/saveWaterDefenceItemList',
					data: JSON.stringify(that.xunjian.params),
					contentType: 'application/json',
					success: function(result) {
						if (result.data) {
							that.$message.success("保存成功！")
						}
					},
				})
			},

			addData() {
				that.activeName = ""
				setTimeout(function() {
					that.activeName = "one"
					that.visible1 = true
					that.form = {}
					that.parameter = {
						list: []
					}
					that.materialList = []
					that.inspectItemList = []
					that.parameterInspectStatusList = []
					that.$forceUpdate()
				}, 100)
			},


			//编辑
			editThis(item) {
				item.isEdit = true
				
				that.form = item
				if (that.form.imgId) {
					that.fileList = [{
						name: '图片',
						url: fileViewUrl + that.form.imgId
					}]
				} else {
					that.fileList = []
				}
				that.productList = item.productList
				that.parameter.list = item.parameterList
				that.materialList = item.materialList
				that.inspectItemList = item.inspectItemList
				that.visible1 = true
				that.getDscRunList()
				that.getParameterInspectStatusList()

				if (item.parameterList && item.parameterList.length) {
					for (let index in item.parameterList) {
						let item2 = item.parameterList[index]
						that.ajax({
							url: '/dcs/parameter/list',
							data: {
								mn: item2.dcsMn,
							},
							contentType: 'application/x-www-form-urlencoded',
							success: function(result) {
								that.dcsAllRunList[index] = result.data
							},
						})
					}
				}
				that.$nextTick(() => {
					that.$refs.upload.clearFiles()
				})
			},

			getParameterInspectStatusList() {
				that.ajax({
					url: '/waterOutlet/getParameterInspectStatusList',
					data: {
						defenceId: that.form.id
					},
					success: function(data) {
						if (data.status == 1) that.parameterInspectStatusList = data.data;
						that.getWaitSelectPollutionList()
						that.$forceUpdate()
					}
				});
			},

			load() {
				if (that.totalPage >= that.pageIndex) return false
				that.pageIndex += 1
				that.getDataList()
			},

			addMaterial() {
				if (!that.form.id) {
					return that.$message({
						message: '请先填写基本设施信息',
						type: 'error'
					});
				}
				that.material = {
					materialType: '',
					ingredientList: []
				}
				that.visible3 = true
				that.material.defenceId = that.form.id
			},

			//添加有害元素
			addIngredientList() {
				that.material.ingredientList.push({
					ingredientName: '',
					percent: ''
				})
			},


			deleteIngredientList(index) {
				that.material.ingredientList.splice(index, 1)
			},

			//保存原辅料
			saveMaterial() {
				if (that.materialList.length == 0) {
					return that.$message({
						message: '请填写原辅料信息',
						type: 'warning'
					});
				}

				that.ajax({
					url: '/waterOutletDefence/batchSaveMaterials',
					data: JSON.stringify({
						defenceId: that.form.id,
						materialList: that.materialList
					}),
					contentType: 'application/json',
					success: function(result) {
						if (result.data) {
							that.$message.success("保存成功！")
						}
					},
				})
			},

			//删除原辅料
			deleteMaterial(item) {
				this.$confirm('是否确定删除此原辅料?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					that.ajax({
						url: '/waterOutlet/deleteWaterOutletMaterial',
						data: {
							waterOutletMaterialId: item.id
						},
						contentType: 'application/x-www-form-urlencoded',
						success: function(result) {
							if (result.data) {
								that.getProductionEquipmentBaseModelById()
							}
						},
					})
				})
			},

			//获取基本信息
			getProductionEquipmentBaseModelById() {
				that.ajax({
					url: '/waterOutletDefence/getWaterDefenceByDefenceId?ticketId=' +
						that.params.ticketId,
					data: {
						defenceId: that.form.id
					},
					contentType: 'application/x-www-form-urlencoded',
					success: function(result) {
						if (result.data) {
							that.productList = result.data.productList
							that.materialList = result.data.materialList
							that.inspectItemList = result.data.inspectItemList
						}
					},
				})
			},

			//新增规格参数
			addParameter() {
				that.parameter.list.push({
					parameterName: '', // 规格参数
					designValueType: 'EXACT_VALUE',
					minDesignValue: '',
					maxDesignValue: '',
					designValueStr: '',
					valueType: 'NUMBER',
					isInspect: true,
					dcsMn: '',
					dcsCode: ''
				})
			},

			//删除一个规格
			deleteParameter(index) {
				that.parameter.list.splice(index, 1)
			},

			//保存规格
			saveParameter(step) {
				if (!that.form.id) {
					return that.$message({
						message: '请先填写基本设施信息',
						type: 'error'
					});
				}

				if (that.parameter.list.length == 0) {
					return that.$message({
						message: '请填写设施规格参数',
						type: 'warning'
					});
				}

				that.ajax({
					url: '/waterOutlet/saveWaterOutletParameterList?ticketId=' +
						that.params.ticketId,
					data: JSON.stringify({
						outletId: that.outletId,
						defenceId: that.form.id,
						dcsMn: that.form.dcsMn,
						dcsRun: that.form.dcsRun,
						parameterList: that.parameter.list,
						dcsRunStd: that.form.dcsRunStd,
						videoIdList: that.form.videoIdList
					}),
					contentType: 'application/json',
					success: function(result) {
						if (result.data) {
							if (step == 2) that.activeName = "three"
							that.getParameterInspectStatusList()
							return that.$message({
								message: '保存成功！',
								type: 'success'
							});
						}
					},
				})
			},

			handleClick(tab, event) {
				if (tab.name != "one") {
					if (!that.form.id) {
						that.activeName = "one"
						return that.$message({
							message: '请先完善设施信息',
							type: 'warning'
						});
					}
				}
			},

			saveInfo(step) {
				this.$refs['form'].validate(function(valid) {
					if (valid) {
						that.ajax({
							url: '/waterOutletDefence/saveWaterDefence?ticketId=' +
								that.params.ticketId,
							data: JSON.stringify(Object.assign({
								outletId: that.outletId,
							}, that.form)),
							contentType: 'application/json',
							success: function(result) {
								if (result.data) {
									if (!that.form.id) that.form.id = result.data
									that.getWaitSelectPollutionList()
								}
								if (step == 2) that.activeName = "two"
								that.$message({
									message: '保存成功！',
									type: 'success'
								});

								that.$emit("success", that.form);
							},
						})
					}
				})
			},

			getWaitSelectPollutionList() {
				that.ajax({
					url: '/waterOutletDefence/pollution/getWaitSelectPollutionList',
					data: {
						outletId: that.outletId,
						defenceId: that.form.id
					},
					success: function(data) {
						if (data.status == 1) that.pollutionList = data.data;
					}
				});
			},

			getDataList(isShow = true) {
				that.ajax({
					url: '/waterOutletDefence/getWaterDefenceListByOutletId',
					data: {
						//outletId: that.outletId,
					},
					contentType: 'application/x-www-form-urlencoded',
					success: function(result) {
						if (result.data) {
							that.dataList[that.pageIndex] = result.data
							that.totalPage = 1
							that.$forceUpdate()
							//console.log(that.dataList)
						}
					},
				}, isShow)
			},


		}
	}
</script>


<style scoped>
	.display_Flex_Bet {
		display: flex;
		justify-content: space-between;
	}

	>>>.el-upload--picture-card {
		width: 80px;
		height: 80px;
		line-height: 92px;
	}

	>>>.el-upload-list--picture-card .el-upload-list__item {
		width: 80px;
		height: 80px;
	}
</style>